#include "label.h"
#include <QDebug>
#include <QMouseEvent>

Label::Label(QWidget *parent):QLabel(parent)
{
    //开启鼠标移动事件
    this->setMouseTracking(true);
}

//鼠标的左键，右键和滚轮键都会触发这个事件
void Label::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton){
        qDebug() << "左键被按下";
    }else if(event->button() ==Qt::RightButton){
        qDebug() << "右键被按下";
    }else if(event->button() == Qt::MidButton){
        qDebug() << "滚轮键被按下";
    }

    //这个形参就包含了鼠标点击时的位置信息
    qDebug() << "mousePressEvent: " << event->x() << ", " << event->y();

    //这个位置信息是相对于整个屏幕的
//    qDebug() << "mousePressEvent: " << event->globalX() << ", " << event->globalY();
}

void Label::mouseReleaseEvent(QMouseEvent *event)
{
    qDebug() << "mouseReleaseEvent: " << event->x() << ", " << event->y();
}

//Qt默认不会出发这个事件，因为这个事件对硬件资源的消耗太大了
//如果要开启这个事件需要setMouseTracking为true
void Label::mouseMoveEvent(QMouseEvent *event)
{
    qDebug() << "mouseMoveEvent: " << event->x() << ", " << event->y();
}

void Label::mouseDoubleClickEvent(QMouseEvent *event)
{
    qDebug() << "mouseDoubleClickEvent: " << event->x() << ", " << event->y();
}

//鼠标滚轮滚动chu'fa'de'shi'jian
void Label::wheelEvent(QWheelEvent *event)
{
    //打印滚轮滚动的距离
    qDebug() << event->delta();
}
